package GUI;

import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class MainMenu extends JFrame {

	private static MainMenu instance;
	private JPanel contentPane;
	private CrOMng manager;
	private IorP ip;
	private PorC pork;
	private About about;

	/**
	 * Launch the application.
	 */

	 public static MainMenu getInstance()
	    {
	        if(instance == null)
	        {
	            instance = new MainMenu();
	        }
	        return instance;
	    }
	    
	
	/**
	 * Create the frame.
	 */
	private MainMenu() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 300, 230);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JMenuBar menuBar = new JMenuBar();
		menuBar.setBounds(0, 0, 434, 20);
		contentPane.add(menuBar);
		
		JMenu mnNewMenu = new JMenu("File");
		menuBar.add(mnNewMenu);
		
		JMenuItem mntmExit = new JMenuItem("Exit");
		mntmExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				dispose();
			}
		});
		mnNewMenu.add(mntmExit);
		
		JMenu mnManagement = new JMenu("Management");
		menuBar.add(mnManagement);
		
		JMenuItem mntmStaff = new JMenuItem("Staff");
		mntmStaff.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				manager= new CrOMng("s");
				manager.setVisible(true);
				dispose();
			}
		});
		mnManagement.add(mntmStaff);
		
		JMenuItem mntmDiscount = new JMenuItem("Discount");
		mntmDiscount.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				manager= new CrOMng("dis");
				manager.setVisible(true);
				dispose();
			}
		});
		mnManagement.add(mntmDiscount);
		
		JMenuItem mntmDelivery = new JMenuItem("Delivery");
		mntmDelivery.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				manager= new CrOMng("del");
				manager.setVisible(true);
				dispose();
			}
		});
		mnManagement.add(mntmDelivery);
		
		JMenu mnAbout = new JMenu("About");
		menuBar.add(mnAbout);
		
		JMenuItem mntmAbout = new JMenuItem("About");
		mntmAbout.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				about = new About();
				about.setVisible(true);
				dispose();
			}
		});
		mnAbout.add(mntmAbout);

		JButton btnOrder = new JButton("Order");
		btnOrder.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				manager= new CrOMng("o");
				manager.setVisible(true);
				dispose();
			}
		});
		btnOrder.setBounds(30, 50, 100, 50);
		contentPane.add(btnOrder);
		
		JButton btnRent = new JButton("Rent");
		btnRent.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				manager= new CrOMng("r");
				manager.setVisible(true);
				dispose();
			}
		});
		btnRent.setBounds(150, 50, 100, 50);
		contentPane.add(btnRent);
		
		JButton btnMembers = new JButton("Members");
		btnMembers.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				manager=new CrOMng("m");
				manager.setVisible(true);
				dispose();
			}
		});
		btnMembers.setBounds(30, 120, 100, 50);
		contentPane.add(btnMembers);
		
		JButton btnInventory = new JButton("Inventory");
		btnInventory.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				ip = new IorP();
				ip.setVisible(true);
				dispose();
			}
		});
		btnInventory.setBounds(150, 120, 100, 50);
		contentPane.add(btnInventory);
	}

}
